<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/3/2
  Time: 11:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="../common/mytaglibs.jsp"%>
<html>
<head>
    <title>欢迎登录新闻网</title>
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/news/css/login.css";
    %>
    <style>
        @import url('<%=basePath%>');
    </style>
</head>
<body>
<div class="header">
    <img src="<%=request.getContextPath() %>/images/news_logo.png" id="logo" />
    <span>欢迎登陆</span>
</div>
<div class="center">
<div class="reg_page">
<p class="mtitle">新       闻       网</p>
<p class="ftitle">NEWS SYSTEM</p>
<form method="post" action="<%=request.getContextPath()%>/signIn">
    <input type="text" name="username" class="userinfo" placeholder="请输入用户名" onblur="checkUsername(this)" /><span id="userTips"></span><br>
    <input type="password" name="password" class="userinfo" placeholder="请输入密码" /><span id="pwdTips"></span><br>
    <input type="submit" value="登录" id="sub" />
    <input type="reset" value="重置" id="res" /><br>
    <p class="reg"><a href="/">没有账号？点击注册</a> </p>
</form>
</div>
</div>
<%@include file="../common/footertopic.jsp" %>
</body>

<script>

    function checkUsername(obj){
        let username = obj.value;
        console.log(username);
        if (username){
        //ajax传输数据至服务器
            $.post("${ctx}/checkUsername",{
                    username:username,
                },
                function(data,status){
                    var myObj = JSON.parse(data);

                    let msg = myObj.msg;

                    if (msg=='success'){
                        document.getElementById("userTips").innerHTML='';
                    }else if (msg == 'fail'){
                        document.getElementById("userTips").innerHTML='<span style="color: red">用户不存在</span>';
                    }else {
                        document.getElementById("userTips").innerHTML='';
                    }
                });
        }
    }
    <%--function login(){--%>
    <%--    var username = document.getElementById("username");--%>
    <%--    var password = document.getElementById("password");--%>
    <%--        //ajax传输数据至服务器--%>
    <%--        $.post("${ctx}/signIn",{--%>
    <%--                username:username,--%>
    <%--                password:password--%>
    <%--            },--%>
    <%--            function(data,status){--%>
    <%--                var myObj = JSON.parse(data);--%>

    <%--                let msg = myObj.msg;--%>
    <%--                debugger--%>
    <%--                if (msg == "fail"){--%>
    <%--                    alert("密码错误！");--%>
    <%--                }--%>
    <%--            });--%>

    <%--}--%>




</script>

</html>
